#!/usr/bin/env python

b = 1
B = 8
K = 1024
M = K * K
G = K * K * K
Kb = K * b
KB = K * B
Mb = K * Kb
MB = K * KB
Gb = K * Mb
GB = K * MB
PROPAGATION_DELAY = 0.04e-6  # seconds 0.04e-6
inDir = "Input/"
outDir = "Output/"

# Node Role
Host = 0
ToR = 1
Core = 2
OCS = 3

# Routing Type
Shortest = 0
K_Shortest = 1
Residual = 2

# Energy
PortPower = 1
EPSPower = 8.75  #
OCSPower = 0.14  #


def GetNodeRole(nodeId, hosts_num, tors_num, cores_num=1):
    if nodeId <= hosts_num:
        return Host
    elif nodeId <= hosts_num + tors_num:
        return ToR
    elif nodeId <= hosts_num + tors_num + cores_num:
        return Core
    else:
        return OCS


def GetToRId(hostId, host_num):
    return (hostId - 1) / host_num + 1


def ConvertToNodeId(id, role, hosts_num, tors_num, cores_num=1):
    """
    Convert regular device id into node id.
    Four roles are defined: 0:Host, 1:ToR, 2:Core
    """
    if role == 0:
        return id
    elif role == 1:
        return id + hosts_num
    elif role == 2:
        return id + hosts_num + tors_num
    else:
        return id + hosts_num + tors_num + cores_num